package com.example.springbootaccesslimit.entry;

import com.example.springbootaccesslimit.enums.CodeMsg;

/**
 * @author lxiaol
 * @date 2022年02月09日 22:36
 */
public class Result<T> {

    private int code;

    private String msg;

    private T data;

    private Result() {
    }

    protected Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    protected Result(CodeMsg cm) {
        this.code = cm.getCode();
        this.msg = cm.getMsg();
    }

    protected Result(CodeMsg cm, T data) {
        this.code = cm.getCode();
        this.msg = cm.getMsg();
        this.data = data;
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(CodeMsg.SUCCESS, data);
    }

    public static <T> Result<T> codeMsg(CodeMsg cm) {
        return new Result<>(cm);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}